Omplus.base.define(Omplus.models.Model, {
    omplusName:"AnketariSearch",
    controller:"userController",
    value:{
        "username":{
            omplusType:"String"
        },
        delta:{
            omplusType:"Number",
            value:5
        },
        start:{
            omplusType:"Number",
            value:0
        }
    }
});

Omplus.base.define(Omplus.models.Model, {
    omplusName:"AnketariSearchResults",
    controller:"userController",
    value:{
        users:{
            omplusType:"Array",
            omplusProto:"UsersSearchModelProto"
        },
        total:{
            omplusType:"Number"
        }
    }
});

Omplus.base.define(Omplus.models.SingleChooser, {
    omplusName:"anketariChooser",
    controller:"userController",
    omplusProto:"UserProto"
});

Omplus.base
    .define(
    Omplus.views.ManagementPanel,
    {
        omplusName:"anketariPanel",
        controller:"userController",
        renderTo:"managements",
        models:{
            chooser:"anketariChooser",
            search:"AnketariSearch",
            searchResult:"AnketariSearchResults",
            searchResultList:"users",
            forDisplay:"username"
        },
        views:{
            chooser:{
                title:"Assets.list.users_label.localValue",
                components:[
                    {
                        omplusName:"usersTabs",
                        omplusType:"OpeningTabPanel",
                        omplusProto:"OpeningUsersTabView",
                        controller:"userController",
                        model:"userChooser",
                        showModel:"username",
                        onChange:function(){
                        }
                    }
                ]
            },
            search:[
                {
                    model:"AnketariSearch.username",
                    labelModel:"Assets.list.anketar_label.localValue",
    				inputCssClasses:["no-transform"]
                },
                {
                    // Per page
                    inputType:"Select",
                    model:"PerPages",
                    showModel:"number",
                    current:"forAnketari",
                    controller:"languageController",
                    labelModel:"Assets.list.label_per_page.localValue",
                    perPage:true
                },
                {
                    // Search button
                    inputType:"Button",
                    controller:"languageController",
                    model:"Assets.list.label_search_button.localValue",
                    cssClasses:[ "search-button" ],
                    labelWidth:"0%",
                    inputWidth:"100%",
                    searchButton:true
                }
            ],
            searchResult:[
                {
                    labelModel:"Assets.list.user_id_label.localValue",
                    width:"100px",
                    omplusType:"Label",
                    model:"id"
                },
                {
                    labelModel:"Assets.list.username_label.localValue",
                    width:"150px",
                    omplusType:"Label",
                    model:"username"
                },
                {
                    labelModel:"Assets.list.name_label.localValue",
                    width:"150px",
                    omplusType:"Label",
                    model:"name"
                },
                {
                    labelModel:"Assets.list.last_name_label.localValue",
                    width:"150px",
                    omplusType:"Label",
                    model:"last_name"
                },
                {
                    labelModel:"Assets.list.kontrolor_label.localValue",
                    width:"150px",
                    omplusType:"Label",
                    model:"kontrolor"
                },
                {
                    omplusType:"Button",
                    model:"Assets.list.label_edit.localValue",
                    width:"160px",
                    controller:"languageController",
                    click:function () {
                        var anketar = $(this).closest(".tableRow").find("label:first").text();
                        Omplus.globals.getObject("EditAnketari.id").setValue(anketar);
                        Omplus.globals.getObject("EditAnketariDialog").show();
                    }
                }
            ]
        }
    });

Omplus.base.define(Omplus.models.Model, {
    omplusName:"EditAnketari",
    controller:"userController",
    value:{
        kontrolor_id:{
            omplusType:"Number",
            synchroniseWith:"Kontrolori.forAnketari.id"
        },
        "id":{
            omplusType:"Number"
        }
    },
    actions:[
        {
            omplusType:"Get",
            omplusName:"editKontrolor",
            proxy:{
                omplusType:"AjaxProxy"
            },
            responseModel:"EditAnketari",
            requestModel:"EditAnketari",
            callback: function(){
                Omplus.globals.getObject("anketariPanel").getAction("searchResult").run();
            }
        }
    ]
});

Omplus.base.define(Omplus.views.Dialog, {
    omplusName:"EditAnketariDialog",
    width:"500px",
    height:"120px",
    components:[
        {
            omplusType:"LabelInputPair",
            omplusName:"editAnketariKontrolor",
            labelModel:"Assets.list.kontrolor_label.localValue",
            labelController:"languageController",
            inputType:"Select",
            model:"Kontrolori",
            current:"forAnketari",
            showModel:"username",
            controller:"languageController"
        }
    ],
    confirmClick:function () {
        Omplus.globals.getObject("EditAnketari").getAction("editKontrolor").run();
        Omplus.globals.getObject("EditAnketariDialog").hide();
    }
});